/*
 * @Date: 2023-09-12 10:28:42
 * @LastEditTime: 2023-09-12 11:27:38
 * @Description: keep-alive 动态组件缓存
 */

import { defineStore } from 'pinia';
import { ref } from 'vue';

export const keepAliveStore = defineStore('keepAliveStore', () => {
	const include = ref<Array<string>>([]);
	// 是否需要刷新接口
	const isRefresh = ref<boolean>(false);
	// 存储include
	const setInclude = (val: string) => {
		if (!include.value.includes(val)) {
			include.value.push(val);
		}
	};
	// 删除
	const removeInclude = (val: string) => {
		const index = include.value.indexOf(val);
		if (index !== -1) {
			include.value = include.value.splice(index, 1);
		}
	};

	const setRefresh = (val: boolean) => {
		isRefresh.value = val;
	};

	return {
		include,
		isRefresh,
		setInclude,
		removeInclude,
		setRefresh
	};
});
